<?php if (!defined('BASEPATH'))  exit('No direct script access allowed');
/**
 * @filesource team_grid_form.php
 */
if(0){?><script><?php }?>

Ext.define('Hydcrm.team.TeamGridForm', {
    extend: 'Ext.form.Panel',
    
    requires: [
        'Ext.grid.*',
        'Ext.form.*',
        'Ext.layout.container.Column'
    ],
    xtype: 'form-grid',
    id: 'team_info_tab',
    frame: true,
    title: '团队维护',
    closable: true,
    autoScroll: true,
    bodyPadding: 5,
    layout: 'column',

    buttons: [{
        text: '保存',
        iconCls: 'icon-save',
        handler: function() {
            this.up('form').getForm().submit({
                url: Hydcrm.CONF.CONN_URL,
                params:{
                    module: 'team',
                    action: 'save_team', 
                    id: ''       
                }, 
                method: 'POST',
                waitMsg: '正在更新',
                success: function(form, action) {
                    list_team_ds.load();
                    //Ext.Msg.alert('正确信息', action.result.feedback);
                },
                failure: function(form, action) {
                    Ext.Msg.alert('错误信息', action.result.feedback);
                },
                scope: this
            });
        }
    },{
        text: '新增',
        iconCls: 'icon-add',
        handler: function() {//this.up('form').getForm().submit();
            this.up('form').getForm().reset();
        }
    }],

    initComponent: function(){
        var dsTeamProvince = Ext.create('Ext.data.Store', {
            fields: [ 'id','text'],
            proxy: {
                type: 'ajax',
                url: Hydcrm.CONF.CONN_URL,
                extraParams: {
                    module: 'team',
                    action: 'get_province_select'
                },
                reader: {
                    type: 'json',
                    root: Hydcrm.CONF.JSON_READER_ROOT
                }
            },
            autoLoad: true
        });
        var cboTeamProvince = Ext.create('Ext.form.ComboBox', {
            fieldLabel: '所属省份',
            store: dsTeamProvince,
            id:'provinceid',
            name: 'provinceid',
            queryMode: 'local',
            displayField: 'text',
            valueField: 'id',
            editable: false,
            allowBlank: false,
            //labelStyle: 'color:red',
            msgTarget:'side',
            forceSelection: true,
            emptyText:'未选择',
            listeners: {
                select: onTeamProvinceSelect,
                scope: this
            }
        });
        var dsTeamCity = Ext.create('Ext.data.Store', {
            fields: [ 'id','text'],
            proxy: {
                type: 'ajax',
                url: Hydcrm.CONF.CONN_URL,
                extraParams: {
                    module: 'team',
                    action: 'get_city_select',
                    //provinceid: 370000
                },
                reader: {
                    type: 'json',
                    root: Hydcrm.CONF.JSON_READER_ROOT
                }
            },
            autoLoad: true
        });
        var cboTeamCity = Ext.create('Ext.form.ComboBox', {
            fieldLabel: '所属城市',
            store: dsTeamCity,
            id:'cityid',
            name: 'cityid',
            queryMode: 'local',
            displayField: 'text',
            valueField: 'id',
            editable: false,
            allowBlank: false,
            //labelStyle: 'color:red',
            msgTarget:'side',
            forceSelection: true,
            emptyText:'未选择'
        });
        function onTeamProvinceSelect(combo, value) {
            cboTeamCity.enable();
            cboTeamCity.reset();
            dsTeamCity.proxy.extraParams['provinceid'] = value[0].get('id');
            dsTeamCity.load();
        };
        Ext.apply(this, {
            width: '100%',
            fieldDefaults: {
                labelAlign: 'right',
                labelWidth: 100,
                columnWidth: 0.8,
                margin: 8,
                anchor: '48%',
                msgTarget: 'side'
            },

            items: [{
                columnWidth: 0.65,
                xtype: 'gridpanel',
                id: 'team_gridpanel',
                store: list_team_ds,
                height: '400',
                columns: [{
                    text: '团队ID',
                    hidden: true,
                    sortable: false,
                    dataIndex: 'id'
                },{
                    text: '省ID',
                    hidden: true,
                    sortable: false,
                    dataIndex: 'provinceid'
                },{
                    text: '城市ID',
                    hidden: true,
                    sortable: false,
                    dataIndex: 'cityid'
                },{
                    text: '团队名称',
                    flex: 1,
                    sortable: true,
                    dataIndex: 'name'
                }, {
                    text: '所属省',hidden: true,
                    width: 120,
                    sortable: true,
                    dataIndex: 'provincename'
                }, {
                    text: '所属城市',hidden: true,
                    width: 120,
                    sortable: true,
                    dataIndex: 'cityname'
                }, {
                    text: '团队人数',
                    width: 100,
                    sortable: true,
                    dataIndex: 'teamtotal'
                }, {
                    text: '成立时间',
                    width: 100,
                    sortable: true,
                    dataIndex: 'buildtime'
                }, {
                    text: '团队状态',
                    width: 80,
                    sortable: true,
                    renderer: this.renderStatus,
                    dataIndex: 'status'
                }],
                bbar: Ext.create('Ext.PagingToolbar', {
                    store: list_team_ds,
                    displayInfo: true,
                    displayMsg: '显示条目 {0} - {1} of {2}',
                    emptyMsg: "无信息可显示",
                    inputItemWidth: 35,
                    items:[ '-' ]
                }),
                listeners: {
                    scope: this,
                    selectionchange: this.onSelectionChange
                }
            }, {
                columnWidth: 0.35,
                margin: '0 0 0 10',
                xtype: 'fieldset',
                id: 'team_fieldset',
                title:'团队明细',
                layout: 'column',
                defaultType: 'textfield',
                items: [{
                    fieldLabel: '团队ID',
                    name: 'id',
                    xtype: 'hidden'
                },{
                    fieldLabel: '团队名称',
                    name: 'name',
                    allowBlank: false
                },cboTeamProvince,cboTeamCity,{
                    fieldLabel: '团队人数',
                    name: 'teamtotal'
                },{
                    fieldLabel: '成立日期',
                    name: 'buildtime',
                    xtype: 'datefield',
                    format: 'Y-m-d',
                    value: new Date()
                },{
                    xtype: 'radiogroup',
                    fieldLabel: '团队状态',
                    columns: 2,
                    defaults: {
                        name: 'status' //Each radio has the same name so the browser will make sure only one is checked at once
                    },
                    items: [{
                        inputValue: '1',
                        checked: true,
                        boxLabel: '正常'
                    }, {
                        inputValue: '0',
                        boxLabel: '解散'
                    }]
                }]
            }]
        });
        this.callParent();
    },
    onSelectionChange: function(model, records) {
        var rec = records[0];
        if (rec) { //alert(rec.get('provinceid'));
            Ext.getCmp('cityid').enable();
            Ext.getCmp('cityid').reset();
            Ext.getCmp('cityid').getStore().proxy.extraParams['provinceid'] = rec.get('provinceid');
            Ext.getCmp('cityid').getStore().load();
            
            this.getForm().loadRecord(rec);
        }
    },
    renderStatus: function(val){ //alert(val);
        switch (val) {
            case '0':
                return '解散';
            case '1':
                return '正常';
        }
    }
});

/* End of file team_web_panel.php */
/* Location: ./system/modules/team/views/team_web_panel.php */